package com.ww.springboot.boot.algorithm.leetcode1;

/**
 * 描述：
 *
 * @author 🧑 ‍wanwei
 * @since 2022-03-11 09:49
 */
public class AH50Pow {
    public static void main(String[] args) {
        //不理解这个结果
        System.out.println(Math.pow(2,-2147483648));

        System.out.println(myPow(2.00000, -2147483648));
    }

    public static double myPow(double x, int n) {
        if (n == 0) {
            return 1;
        }
        if(x == 1){
            return 1;
        }
        Boolean flag = false;
        if (n < 0) {
            flag = true;
            n = 0 - n;
        }


        double xx = 1;
        while (n > 0) {
            xx *= x;
            n--;
        }

        if (flag) {
            return 1 / xx;
        }
        return xx;
    }
}
